import { DataEvent } from "../../events/DataEvent";
type int = number;
//class LuckyBagCard
    
    export  class LuckyBagCard /* flash.display.Sprite */
    {
        constructor(arg1: Object /* flash.geom.Rectangle */)
        {
            
            this._mCover = new Object /* flash.display.Sprite */();
            this._mBackCover = new Object /* flash.display.Sprite */();
            this._container = new Object /* flash.display.Sprite */();
            this._rect = arg1;
            addChild(this._container);
            this._container.addChild(this._mCover);
            this._container.addChild(this._mBackCover);
            this._mCover.visible = true;
            this._mBackCover.visible = false;
            this._mBackCover.scaleX = -1;
            this._mCover.x = -Math.floor(arg1.width * 0.5);
            this._mBackCover.x = Math.floor(arg1.width * 0.5);
            addEventListener(flash.events.Event.ENTER_FRAME, this.onRender, false, 0, true);
            return;
        }

        /* internal  */onRender(arg1: Object /* flash.events.Event */): void
        {
            var loc1=0;
            if (this._allowAnamation) 
            {
                this._rotationCount = this._rotationCount + this._speed;
                this._container.rotationY = this._container.rotationY + this._speed;
                loc1 = this._rotationCount % 180;
                if (loc1 != 0) 
                {
                    if (loc1 > 90) 
                    {
                        this.setCoversVisible();
                    }
                }
                else 
                {
                    this._allowAnamation = false;
                    this._isAnamating = false;
                    this.dispatchEvent(new DataEvent("LUCKYBAGCARFLIPCOMPLETE", null, false, true, true));
                }
            }
            return;
        }

        public doFlip(): void
        {
            if (this._isAnamating) 
            {
                return;
            }
            this._allowAnamation = true;
            this._isAnamating = true;
            var loc1;
            var loc2=((loc1 = this)._clickCount + 1);
            loc1._clickCount = loc2;
            return;
        }

        public doFlipWithoutAnimate(): void
        {
            var loc1;
            var loc2=((loc1 = this)._clickCount + 1);
            loc1._clickCount = loc2;
            this.setCoversVisible();
            this._container.rotationY = this._container.rotationY + 180;
            return;
        }

        /* internal  */setCoversVisible(): void
        {
            this._isCover = this._clickCount % 2 == 0;
            this._mCover.visible = this._isCover;
            this._mBackCover.visible = !this._isCover;
            return;
        }

        public get cover(): Object /* flash.display.Sprite */
        {
            return this._mCover;
        }

        public get backCover(): Object /* flash.display.Sprite */
        {
            return this._mBackCover;
        }

        public get speed(): int
        {
            return this._speed;
        }

        public set speed(arg1: int)
        {
            if (arg1 < 1) 
            {
                arg1 = 1;
            }
            if (arg1 > 6) 
            {
                arg1 = 6;
            }
            this._speed = Math.ceil(arg1);
            return;
        }

        public get isAnamating(): Boolean
        {
            return this._isAnamating;
        }

        /* internal */ /* var */_mCover: Object /* flash.display.Sprite */;

        /* internal */ /* var */_mBackCover: Object /* flash.display.Sprite */;

        /* internal */ /* var */_container: Object /* flash.display.Sprite */;

        /* internal */ /* var */_isAnamating: Boolean=false;

        /* internal */ /* var */_isCover: Boolean=true;

        /* internal */ /* var */_allowAnamation: Boolean=false;

        /* internal */ /* var */_speed: int=1;

        /* internal */ /* var */_rotationCount: uint=0;

        /* internal */ /* var */_rect: Object /* flash.geom.Rectangle */;

        /* internal */ /* var */_clickCount: uint=0;
    }
